﻿enyo.kind({
    name: "AnalysisService",
    kind: enyo.VFlexBox,
    components: [
        {kind: "PageHeader", components: [
            {content: "SBS Analysis Service"}
        ]},
        {flex: 1, kind: "Pane", components: [
            {flex: 1, kind: "Scroller", components: [
				{name: "content", kind: "HtmlContent", content: "", style: "font-size: 16px"}
            ]}
        ]},
        {kind: "Toolbar", components: [
		    {name: "btnLaunch",kind: "IconButton", caption: "Launch", onclick: "btnClick", style: "padding: 5px 40px 5px 40px;"}
        ]},
		{name: "getResponse", kind: "WebService",
            method: "POST",
            url: "http://16.158.83.140:8080/analysis-1.0/retrieveAllListAnalysisType",
            onSuccess: "gotResponse",
            onFailure: "gotResponseFailure",
			headers: { "X-HP-SBS-ApplicationId": "sharedbusws1", 
				"X-HP-SBS-ApplicationKey": "N3v3rsurr3nd3r", 
				"X-HP-SBS-TestRequest": "false", 
				"X-HP-SBS-SessionContext": "3999e3e6-782f-4354-85ed-7d43d3e0a4ff" 
			}
		}
    ],
	message: function(inMsg, padding ,inColor) {
		this.$.content.setContent(this.$.content.content + '<div style="padding: 1px ' + padding + 'px; border-bottom: 1px solid gray; background-color: ' + inColor + ';">' + inMsg + "</div>");
		this.$.scroller.scrollToBottom();
	},
	btnClick: function() {
		this.$.btnLaunch.setCaption("");
		this.$.btnLaunch.setIcon("images/ajax-loader.gif");
		this.$.content.setContent("");
	    this.$.getResponse.call();
	},
	gotResponse: function(inSender, inResponse, inRequest) {
		this.$.btnLaunch.setCaption("Launch");
		this.$.btnLaunch.setIcon("");
		if(inResponse.statusCode == 200) {
			for(var i = 0; i < inResponse.payload.length; i++) {
			    var playload = inResponse.payload[i];
				this.message(playload.name + " : " + playload.description, 8, "white");
				for(var j = 0; j < playload.supportedLocale.length; j++) {
				    this.message(playload.supportedLocale[j].localeCode + " : " + playload.supportedLocale[j].displayLanguage, 16, "");
				}
			}
		}
		else {
			this.message("Error Response:" + inResponse.statusCode, 8,  "white");
		}
	},
	gotResponseFailure: function(inSender, inResponse, inRequest) {
		this.message("Error", 8, "white");
	}
});